package com.zhuoya.healthcard.util;

import android.content.*;

import java.util.*;

import android.media.*;
import android.net.*;

import com.zhuoya.healthcard.entity.*;

public class SoundPoolHelper {
    private static final String TAG;
    private Context mContext;
    private volatile boolean mIsEnableSound;
    private volatile boolean mIsPlaying;
    private volatile long mPlayDuration;
    private HashMap<Integer, Long> mPlayDurationMap;
    private FaceStatusEnum mPlaySoundStatusEnum;
    private volatile long mPlayTime;

    static {
        TAG = SoundPoolHelper.class.getSimpleName();
    }

    public SoundPoolHelper(final Context mContext) {
        this.mPlayDuration = 0L;
        this.mPlayTime = 0L;
        this.mIsPlaying = false;
        this.mIsEnableSound = true;
        this.mPlayDurationMap = new HashMap<Integer, Long>();
        this.mContext = mContext;
    }

    private long getSoundDuration(final int n) {
        final long n2 = 600L;
        if (this.mPlayDurationMap.containsKey(n)) {
            return this.mPlayDurationMap.get(n);
        }
        System.currentTimeMillis();
        final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        long n3 = n2;
        long n4 = n2;
        long n5 = n2;
        try {
            final StringBuilder sb = new StringBuilder();
            n3 = n2;
            n4 = n2;
            n5 = n2;
            sb.append("android.resource://");
            n3 = n2;
            n4 = n2;
            n5 = n2;
            sb.append(this.mContext.getPackageName());
            n3 = n2;
            n4 = n2;
            n5 = n2;
            sb.append("/");
            n3 = n2;
            n4 = n2;
            n5 = n2;
            sb.append(n);
            n3 = n2;
            n4 = n2;
            n5 = n2;
            final Uri parse = Uri.parse(sb.toString());
            n3 = n2;
            n4 = n2;
            n5 = n2;
            mediaMetadataRetriever.setDataSource(this.mContext, parse);
            n3 = n2;
            n4 = n2;
            n5 = n2;
            final long n6 = n5 = (n4 = (n3 = Long.valueOf(mediaMetadataRetriever.extractMetadata(9)) + 0L));
            this.mPlayDurationMap.put(n, n6);
            return n6;
        } catch (IllegalStateException ex2) {
            ex2.printStackTrace();
        } catch (IllegalArgumentException ex3) {
            ex3.printStackTrace();
            n4 = n5;
        } catch (Exception ex) {
            ex.printStackTrace();
            return n3;
        }
        return n4;
    }

    public boolean getEnableSound() {
        return this.mIsEnableSound;
    }

    public long getPlayDuration() {
        return this.mPlayDuration;
    }

    public boolean playSound(final FaceStatusEnum mPlaySoundStatusEnum) {
        if (this.mIsPlaying = (System.currentTimeMillis() - SoundPlayer.playTime < this.mPlayDuration)) {
            return false;
        }
        if (this.mPlaySoundStatusEnum == mPlaySoundStatusEnum && System.currentTimeMillis() - this.mPlayTime < FaceEnvironment.TIME_TIPS_REPEAT) {
            return false;
        }
        this.mIsPlaying = true;
        this.mPlaySoundStatusEnum = mPlaySoundStatusEnum;
        this.mPlayDuration = 0L;
        this.mPlayTime = System.currentTimeMillis();
        final int soundId = FaceEnvironment.getSoundId(mPlaySoundStatusEnum);
        if (soundId > 0) {
            this.mPlayDuration = this.getSoundDuration(soundId);
            SoundPlayer.playTime = System.currentTimeMillis();
            if (this.mIsEnableSound) {
                SoundPlayer.play(this.mContext, soundId);
            }
        }
        return this.mIsPlaying;
    }

    public void release() {
        SoundPlayer.release();
        this.mContext = null;
    }

    public void setEnableSound(final boolean mIsEnableSound) {
        this.mIsEnableSound = mIsEnableSound;
    }
}
